<?php

namespace App\Traits;

trait ResponseTrait
{
    /**
     * 返回操作成功数据
     *
     * @return 
     */
    public function success($data = [], $message = '操作成功')
    {
        return $this->jsonReturn(0, $data, $message);
    }

    /**
     * 返回操作失败数据
     *
     * @return 
     */
    public function fail($code, $data = [], $message = '操作失败')
    {
        return $this->jsonReturn($code, $data, $message);
    }

    /**
     * 返回json
     *
     * @return 
     */
    public function jsonReturn($code, array $data, string $message)
    {
        return response()->json([
            'code' => $code,
            'data' => $data,
            'message' => $message,
        ]);
    }
}